AS=/usr/local/mips-cross/bin/mipsel-elf-as
CC=/usr/local/mips-cross/bin/mipsel-elf-gcc
LD=/usr/local/mips-cross/bin/mipsel-elf-ld
OBJCOPY=/usr/local/mips-cross/bin/mipsel-elf-objcopy
OBJDUMP=/usr/local/mips-cross/bin/mipsel-elf-objdump

# do not change these under any circumstances
REQUIRED_CFLAGS=-mips1 -nodefaultlibs -nostartfiles -nostdlib -membedded-data -mno-mips16 -fno-builtin

CUSTOM_CFLAGS= --std=c99 -g -O -fno-data-sections

CFLAGS=$(REQUIRED_CFLAGS) $(CUSTOM_CFLAGS)

INCLUDE=-I../../include/

all:
	$(CC) mm.c -c $(CFLAGS) $(INCLUDE) -o mm.o
	$(AS) -mips1 bootloader.S -o bootloader.o -EL -g
	$(LD) -mips1 -T ../../lib/default.ld mm.o bootloader.o -o mm.elf -EL -g
	$(OBJCOPY) -j .startup.bootvec -j .startup -j .rodata -O binary mm.elf mm.bin
	hexdump -e "1/4 \"%08x\n\"" mm.bin -v > mm.hex
	echo "@e0000" > mm.mem
	hexdump -e "1/1 \"%02x\n\"" mm.bin -v >> mm.mem

dump:
	$(OBJDUMP) -j .startup.bootvec -j .startup -S -D mm.elf -z

symbols:
	$(OBJDUMP) -t mm.elf

sections:
	$(OBJDUMP) -h mm.elf

clean:
	rm -f mm.bin mm.elf mm.hex mm.o bootloader.o
